package com.wjbgn.electronicnian.enums;

import cn.hutool.core.util.RandomUtil;

/**
 * 饺子枚举
 *
 * @author weirx
 * @date 2022/01/21 11:26
 **/
public enum DumplingsEnum {
    LEEK_EGG("韭菜鸡蛋饺子", 1, 1),
    PORK_CELERY("猪肉芹菜饺子", 2, 2),
    BEEF("牛肉饺子", 3, 3),
    PORK_ONION("猪肉大葱饺子", 2, 4),
    THREE_FRESH("三鲜饺子", 3, 5),
    SPANISH_MACKEREL("鲅鱼饺子", 2, 6),
    COINS("硬币饺子", 5, 7),
    SUGAR("红糖饺子", 1, 8);

    public static DumplingsEnum getOrder(int chance) {
        // 如果只有1个饺子，那么十分之一的概率就是百分之十；
        // 那么8个饺子，十分之一就是八百分之八十
        int i = 80;
        // 百分之10的概率相当于在80个当中选中前8个order（1~8）
        // 百分之20相当于在40个当中选中前8个oder(1~8)
        // 百分之50相当于在16个中选择前8个oder（1~8）
        int i1 = chance / 10;
        int i2 = i / i1;
        int random = RandomUtil.randomInt(1, i2);
        if (random <= 8) {
            for (DumplingsEnum dumplingsEnum : DumplingsEnum.values()) {
                if (dumplingsEnum.order == random) {
                    return dumplingsEnum;
                }
            }
        }
        return null;
    }

    public static void main(String[] args) {

    }

    private int order;

    private String name;

    private int hungryNum;

    public String getName() {
        return name;
    }

    public int getHungryNum() {
        return hungryNum;
    }

    DumplingsEnum(String name, int hungryNum, int order) {
        this.name = name;
        this.hungryNum = hungryNum;
        this.order = order;
    }
}
